#include<stdio.h>
#include<fcntl.h>
//利用fileno函数转换为文件描述符
int main(void)
{
	FILE *fp;
	int fd=open("data.txt",O_WRONLY|O_CREAT|O_TRUNC);
	if(fd==-1)
	{
		fputs("file open error",stdout);
		return -1;
	}
	printf("First file descriptor:%d\n",fd);
	fp=fdopen(fd,"w");
	fputs("TCP/IP SOCKET PROGRAMMING\n",fp);
	//int fileno(FILE *stream)
	printf("Second file descriptor:%d\n",fileno(fp));//FILE转换为文件描述符
	fclose(fp);
	return 0;
}
